home *** CD-ROM | disk | FTP | other *** search
/ CD ROM Paradise Collection 4 / CD ROM Paradise Collection 4 1995 Nov.iso / asm / asmlib30.zip / STARTUP.ASM < prev    next >
Assembly Source File  |  1992-05-16  |  2KB  |  89 lines

  1. include    asm.inc
  2.  
  3. extrn    endprog:proc
  4. extrn    breaktrap:proc
  5. extrn    breakrelease:proc
  6. IFDEF    HEAP
  7. extrn    hinit:proc
  8. ENDIF
  9. extrn    mymain:proc
  10.  
  11. ; make LINK search through ASMLIB for external references
  12. ; so I don't have to specify ASMLIB on the command line
  13. IF codesize EQ 1
  14. IF datasize EQ 2
  15. includelib    asmhuge
  16. ELSE
  17. includelib    asmlib
  18. ENDIF
  19. ELSE
  20. includelib    asmsmall
  21. ENDIF
  22.  
  23. stacksize    equ    1024
  24.  
  25. .stack stacksize
  26.  
  27. .data
  28. public    pspseg
  29. pspseg        dw    ?        ; storage for PSP segment
  30.  
  31. IFDEF    HEAP
  32. ; make some space available for the local heap
  33. heapsize    equ    32767
  34. heapbuffer    db    heapsize dup(0)
  35. ENDIF
  36.  
  37. .code
  38. start:
  39. ; start by pointing DS to DGROUP
  40.     mov    ax,@data
  41.     mov    ds,ax
  42.     assume    ds:@data
  43.  
  44. ; save PSP segment for DOS 2.xx
  45.     mov    pspseg,es
  46.  
  47. ; next, release memory beyond the end of the program
  48. ; The file ENDPROG.ASM has a definition for ZSEG, marking the
  49. ; end of the program's code, data and stack area.  I want to
  50. ; release memory beyond ZSEG so I can use DOS function 48h for
  51. ; memory allocation.
  52. ; When linking ENDPROG.OBJ with your other object files, be sure
  53. ; ENDPROG is at the end of your list of object files.  The new segment
  54. ; ZSEG surprises link, and it has little choice but to put ZSEG
  55. ; at the end of the program.
  56.     call    endprog            ; returns AX = last segment 
  57.  
  58.     mov    bx,es            ; first segment (ES = seg PSP)
  59.     sub    bx,ax
  60.     neg    bx            ; size of program in paragraphs
  61.     mov    ah,4Ah            ; resize memory block
  62.     int    21h
  63.  
  64. IFDEF    HEAP
  65. ; need to initialize the heap in order to work properly.  A common cause
  66. ; of bombed programs is failure to initilaize the heap.
  67.     lea    bx,heapbuffer
  68.     mov    ax,heapsize
  69.     call    hinit
  70. ENDIF
  71.  
  72. ; prevent an unintended program crash; trap Ctrl+Break, Ctrl+C and
  73. ; Ctrl+Alt+Del key combinations
  74.     call    breaktrap
  75.  
  76. ; call your main program here
  77.     call    mymain
  78.  
  79. exit:
  80. ; de-activate the Ctrl+Break trap
  81.     call    breakrelease
  82.  
  83. ; normal program exit
  84.     mov    ax,4C00h
  85.     int    21h
  86.  
  87. end    start
  88.     end
  89.